/* eslint-disable @typescript-eslint/no-this-alias */
function throttle (fn, delay) {
  // eslint-disable-next-line no-var
  var t = null,
    begin = new Date().getTime()
  return function() {
    // eslint-disable-next-line no-var
    var _self = this,
      // eslint-disable-next-line prefer-rest-params
      args = arguments,
      cur = new Date().getTime()

    clearTimeout(t)
    if(cur - begin >= delay) {
      fn.apply(_self, args)
      begin = cur
    } else {
      t = setTimeout(function() {
        fn.apply(_self, args)
      },delay)
    }
  }
}
// import { ref } from 'vue'
// function throttle (fn, delay) {
//   // eslint-disable-next-line prefer-const
//   let isThtottle = ref(true)
//   return () => {
//     if (!isThtottle.value) return
//     isThtottle.value = false
//     setTimeout(() => {
//       fn()
//       isThtottle.value = true
//     }, delay)
//   }
// }
export {
  throttle
}
